/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bl;

import entity.Employee;
import entity.LeaveType;
import java.util.ArrayList;
import javax.swing.JLabel;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Kien Chinh
 */
public class ModelTableReportDetail extends AbstractTableModel {

    private String[] columnName = {"Leave type", "Quantity", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", "Total"};
    ArrayList<LeaveType> list;
    private EmployeeBusiness business;
    private String year;
    private Employee employee;
    private int count = 0;

    public ModelTableReportDetail(ArrayList<LeaveType> list, String year, Employee employee) {
        this.list = list;
        this.year = year;
        this.employee = employee;
        business = new EmployeeBusiness();
    }

    @Override
    public int getRowCount() {
        return list.size();
    }

    @Override
    public int getColumnCount() {
        return columnName.length;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        LeaveType type = list.get(rowIndex);
        int result = 0;
        switch (columnIndex) {
            case 0:
                return type.getName();
            case 1:
                return type.getQuatity();
            case 2:
                result = business.countLeaveDetailByMonth(employee, "1", type.getTypeID(), year);
                count += result;
                return result;
            case 3:
                result = business.countLeaveDetailByMonth(employee, "2", type.getTypeID(), year);
                count += result;
                return result;
            case 4:
                result = business.countLeaveDetailByMonth(employee, "3", type.getTypeID(), year);
                count += result;
                return result;
            case 5:
                result = business.countLeaveDetailByMonth(employee, "4", type.getTypeID(), year);
                count += result;
                return result;
            case 6:
                result = business.countLeaveDetailByMonth(employee, "5", type.getTypeID(), year);
                count += result;
                return result;
            case 7:
                result = business.countLeaveDetailByMonth(employee, "6", type.getTypeID(), year);
                count += result;
                return result;
            case 8:
                result = business.countLeaveDetailByMonth(employee, "7", type.getTypeID(), year);
                count += result;
                return result;
            case 9:
                result = business.countLeaveDetailByMonth(employee, "8", type.getTypeID(), year);
                count += result;
                return result;
            case 10:
                result = business.countLeaveDetailByMonth(employee, "9", type.getTypeID(), year);
                count += result;
                return result;
            case 11:
                result = business.countLeaveDetailByMonth(employee, "10", type.getTypeID(), year);
                count += result;
                return result;
            case 12:
                result = business.countLeaveDetailByMonth(employee, "11", type.getTypeID(), year);
                count += result;
                return result;
            case 13:
                result = business.countLeaveDetailByMonth(employee, "12", type.getTypeID(), year);
                count += result;
                return result;
            case 14:
                return count;
            default:
                return new Object();
        }
    }

    @Override
    public Class getColumnClass(int columnIndex) {
        switch (columnIndex) {
            case 0:
                return String.class;
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
            case 8:
            case 9:
            case 10:
            case 11:
            case 12:
            case 13:
            case 14:
                return Integer.class;
            default:
                return Object.class;
        }
    }

    @Override
    public String getColumnName(int columnIndex) {
        return columnName[columnIndex];
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }
}
